$(document).ready(function() {
   
	var textoDefault = $('#form_cadastro for').attr('title');
	
	var baseUrl = $("#baseUrl").text();
	$(function(){
		window.prettyPrint && prettyPrint();
		$('#dp1').datepicker({
			format: 'mm-dd-yyyy'
		});
		$('#dp2').datepicker();
		$('#dp3').datepicker();
		$('#dp3').datepicker();
		$('.dpYears').datepicker();
		$('#dpMonths').datepicker();
		

		
		var startDate = new Date(2012,1,20);
		var endDate = new Date(2012,1,25);
		
		$('#dp4').datepicker()
			.on('changeDate', function(ev){
				if (ev.date.valueOf() > endDate.valueOf()){
					$('#alert').show().find('strong').text('The start date can not be greater then the end date');
				} else {
					$('#alert').hide();
					startDate = new Date(ev.date);
					$('#startDate').text($('#dp4').data('date'));
				}
				$('#dp4').datepicker('hide');
			});
		$('#dp5').datepicker()
			.on('changeDate', function(ev){
				if (ev.date.valueOf() < startDate.valueOf()){
					$('#alert').show().find('strong').text('The end date can not be less then the start date');
				} else {
					$('#alert').hide();
					endDate = new Date(ev.date);
					$('#endDate').text($('#dp5').data('date'));
				}
				$('#dp5').datepicker('hide');
			});
	});
	
	 $(".deletar_pessoa").click(function(){
		 
		 if (!confirm("Deseja deletar mesmo?")) return false;
	    	jQuery.ajax({
	            type: "POST",
	            url: baseUrl + '/pessoa/deletar',
	            dataType: "json",
	            data: {
	                nome: $(this).attr('rel') 
	            } ,


	            beforeSend: function (XMLHttpRequest) {
	                
	            },

	            complete: function (XMLHttpRequest, textStatus) {},
	            //@todo verificar porque reload 
	            //esta chamando o reenviar. tipo f5
	            success: function(msg, textStatus){
	                alert('Deletado com sucesso');
	                window.location.reload();
	            }

	        });
	    });
	 
		 
	 $("#filtro1").change(function(){
		 var valor = $(this).val(); 
		 
		 if (valor == 'Rua' || valor == 'Bairro'){
			 $("#vl_filtro").show();
			 $("#vl_filtro-label").show();
			 $("#filtro_aniversario-label").hide();
			 $("#filtro_aniversario-element").hide();
			 $("#sub_filtro_dia").hide();
			 $("#sub_filtro_mes").hide();
			 $("#sub_filtro_mes-label").hide();
			 $("#sub_filtro_dia-label").hide();
		 }else if (valor == 'Aniversario'){
			 $("#vl_filtro").hide();
			 $("#vl_filtro-label").hide();
			 $("#filtro_aniversario-label").show();
			 $("#filtro_aniversario-element").show();
		 }
	 });
	 
	 $("#filtro_aniversario-element").change(function(){
		 var dia  = $("#filtro_aniversario-D").is(":checked");
		 var diaMes = $("#filtro_aniversario-DM").is(":checked");
		 var mes  = $("#filtro_aniversario-M").is(":checked");
		 
		 if (dia){
			 $("#sub_filtro_dia").show();
			 $("#sub_filtro_dia-label").show();
			 $("#sub_filtro_mes").hide();
			 $("#sub_filtro_mes-label").hide();
		 } else if (mes){
			 $("#sub_filtro_mes").show();
			 $("#sub_filtro_mes-label").show();
			 $("#sub_filtro_dia").hide();
			 $("#sub_filtro_dia-label").hide();
			 
		 } else if (diaMes){
			 $("#sub_filtro_dia").show();
			 $("#sub_filtro_mes").show();
			 $("#sub_filtro_mes-label").show();
			 $("#sub_filtro_dia-label").show();
		 }
		 
		 
	 });

});